import re
my_dict = ({'attack': '0',
            'combat_width': '500',
            })

# path
file_path = r"E:\SteamLibrary\steamapps\common\Hearts of Iron IV\common\terrain\00_terrain.txt"

# read file

with open(file_path, 'r', encoding='utf-8') as file:
    content = file.readlines()

for key in my_dict:
    regular_express = key + ' ' + '=' + ' ' + '.*'
    target = key + ' ' + '=' + ' ' + my_dict[key]
    # print(regular_express, target)
    content = [re.sub(regular_express, target, line) for line in content]

# content = [line.replace('is_water = yes', '') for line in content]


# write back

with open(file_path, 'w', encoding='utf-8') as file:

    file.writelines(content)